﻿using AutoMapper;
using Pay.Core;
using Pay.Data;
using Pay.DTO;
using Pay.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pay.Service.AutoMapper {
    
    public class CourseMapper : IStartupDto {
        private IMapperConfigurationExpression _cfg;
        public CourseMapper(IMapperConfigurationExpression cfg) {
            _cfg = cfg;
        }
        public void Execute() {
            Create();
        }
        protected virtual void Create() {
            _cfg.CreateMap<Course, course_dto>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.name, src => src.MapFrom(c => c.Name))
                .ForMember(dest => dest.url, src => src.MapFrom(c => c.Url))
                .ForMember(dest => dest.course_time, src => src.MapFrom(c => c.Time))
                .ForMember(dest => dest.horse, src => src.MapFrom(c => c.Horse))
                .ForMember(dest => dest.is_enable, src => src.MapFrom(c => c.IsEnable))
                   .ForMember(dest => dest.course_hour, src => src.MapFrom(c => c.Time / 3600))
                      .ForMember(dest => dest.course_minute, src => src.MapFrom(c => c.Time%3600/60))
                         .ForMember(dest => dest.course_second, src => src.MapFrom(c => c.Time%3600%60))
                .ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime.ToDateTime()))
                .ForMember(dest => dest.update_time, src => src.MapFrom(c => c.UpdateTime.ToDateTime()));



            _cfg.CreateMap<course_dto, Course>()
                .ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
                .ForMember(dest => dest.Name, src => src.MapFrom(c => c.name))
                .ForMember(dest => dest.Url , src => src.MapFrom(c => c.url ))
                .ForMember(dest => dest.Time, src => src.MapFrom(c => c.course_hour*3600+c.course_minute*60+c.course_second))
                .ForMember(dest => dest.Horse, src => src.MapFrom(c => c.horse))
                .ForMember(dest => dest.IsEnable, src => src.MapFrom(c => c.is_enable))
                .ForMember(dest => dest.CreateTime, src => src.MapFrom(c => c.create_time.ToUnix()))
                .ForMember(dest => dest.UpdateTime, src => src.MapFrom(c => c.update_time.ToUnix()));


        }
    }
}
